import std.stdio;
import std.algorithm;
import std.c.linux.linux;
import std.exception;
import std.math;

/+

compile using GDC:

/opt/project/d/gdc/target/usr/local/bin 

./gdc -rdynamic -o mathdynlib /opt/project/scala-agent3/dlang/dynlibso/dynlibso.d -ldl


+/

void main(){
	double function(double) cosine;
	
	auto libHandle = dlopen("libm.so", RTLD_LAZY);
	writeln("libHandle ", libHandle);
	enforce(libHandle);
	dlerror();    /* Clear any existing error */
	cosine = cast(double function(double)) dlsym(libHandle, "cos");
	enforce(!dlerror());
	writeln("cos(1) ",cos(1), " libm.so ", cos(1));
	dlclose(libHandle);
	enforce(!dlerror());
	writeln("end");
}